package com.zysstudy.studysyntax;

import com.zysstudy.studysyntax.enums.Color;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author zhaoyoushui
 * @date 2023/8/30 17:40
 */

@Controller
@RequestMapping(value = "/study")
public class Study {

    @GetMapping("/zystest")
    @ResponseBody
    public String zysstudy() {

        List list = new ArrayList();
        list.add("Hello");
        list.add(1);
        list.add("abc");
        for (Object value : list) {
            System.out.println(value);
        }
        List list1 = new ArrayList<>();


//        list<> 是泛型
//        List<String> myList;  #必须进行初始化赋值  int a boolean b 多是有默认初始化赋值的 List类型没有

        List<String> myList = new ArrayList<>();
//        List<String> abc = new List<String>();

        int[] ns;
        ns = new int[]{23, 23, 34};
        String[] ts;
        ts = new String[]{"23", "a"};
        String[] ts1 = {"abc", "bcd"};

        int[][] scores = {
                {1, 2, 3},
                {4, 5, 6},
        };

        String a = "a";
        String b = "A".toLowerCase();
        if (a == b) {
            System.out.println("变量a与变量b是相等的" + "a值:" + a + "---b值:" + b);
        } else {
            System.out.println("变量a与变量b是不相等的" + "a值:" + a + "---b值:" + b);
        }
        if (a.equals(b)) {
            System.out.println("equals方法比较变量a与变量b是相等的" + "a值:" + a + "---b值:" + b);
        }
        myList.add("我是字符串1");
        myList.add("我是字符串2");
        myList.add("我是字符串3");
        System.out.println(myList.get(2));


        //如果变量s1为null，equals方法会报NullPointerException：
        String s1 = null;
        if (s1 != null && s1.equals(a)) {

        }

        for (String value : ts1) {
            System.out.println(value);
        }

        System.out.println(Color.GREEN.getColorNumber());


        List<String> list3 = new ArrayList<String>();
        list3.add("xx");

        //引用类型比较 ==与equals
        Person p1 = new Person("lisi",18);
        Person p2 = new Person("lisi",18);
        if (p1.equals(p2)) {
            System.out.println("equals  p1=p1");
        }
        if (p1 == p2) {
            System.out.println("==  p1=p1");
        }
        String str1 = "lisi";
        String str2 = "lisi";
        if (str1 == str2) {
            System.out.println("==  str1=str1");
        }
        if (str1.equals(str2)) {
            System.out.println("equals str1=str1");
        }



        Map<String, Person> map1 = new HashMap<>();
        map1.put("zhangsan",p1);
        map1.put("lisi",p2);
        for(String val:map1.keySet()){
            System.out.println(val);
        }
        for(Map.Entry<String,Person> val:map1.entrySet()){
            String key=val.getKey();
            Person value=val.getValue();
            System.out.println(key+"="+value.name);
        }



        ArrayList<String> list21=new ArrayList<>();
        list21.add("1");
        list21.add("2");
        String [] strs = new String [4];
        this.testFarr(strs);

        return "stutest";



    }

    public <T> T[] testFarr(T[] test){
        System.out.println(test.length);

        return test;
    }
}
